<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <title>ISeeAdmin 【文章列表】 </title>
    <!--    <link rel="stylesheet" href="/static/element/index.css">-->
    <link href="https://cdn.staticfile.org/element-ui/2.12.0/theme-chalk/index.css" rel="stylesheet">
    <link rel="stylesheet" href="/static/iconfont/iconfont.css">
    <link rel="stylesheet" href="/static/css/common.css">
    <link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
    <!--    开发环境-->
    <!--        <script src="/static/js/iseeadmin.js"></script>-->
    <!--    正式环境-->
    <script src="/static/js/iseeadmin.min.js"></script>
    <script src="/static/js/menu.js"></script>
    <!--    开发环境-->
    <!--    <script src="/static/js/vue.js"></script>-->
    <!--    正式环境-->
    <!--        <script src="/static/js/vue.min.js"></script>-->
    <script src="https://cdn.staticfile.org/vue/2.6.10/vue.min.js"></script>
    <!--    <script src="/static/element/index.js"></script>-->
    <script src="https://cdn.staticfile.org/element-ui/2.12.0/index.js"></script>
    <!--    <script src="/static/js/axios.min.js"></script>-->
    <script src="https://cdn.staticfile.org/quill/1.3.7/quill.min.js"></script>
    <style>
        .form-item-width {
            width: 260px;
        }

        .el-select .el-input {
            width: 100px;
        }

        .input-with-select {
            width: 260px;
        }

        .input-with-select .el-input-group__prepend {
            background-color: #fff;

        }
    </style>
</head>
<body>
<div id="app" v-cloak>
    <el-container style="height: 100%;min-height:100vh;">
        <el-aside v-show="iseeData.asideShow" width="210px">
            <!--            左侧logo 开始-->
            <div class="aside-logo">
                <img class="aside-logo-img" src="/static/images/logo.png"
                     alt=""> ISeeAdmin
            </div>
            <!--            左侧logo 结束-->
            <!--            左侧菜单 开始-->
            <el-menu @select="iseeMenuOpen" style="width: 210px;"
                     unique-opened
                     :default-active="iseeData.defaultActive"
                     background-color="#304156"
                     text-color="#bfcbd9"
                     active-text-color="#409eff">
                <iseemenu :menu="iseeData.menu"></iseemenu>
            </el-menu>
            <!--            左侧菜单 结束-->
        </el-aside>

        <el-container>
            <el-header height="83px">
                <div class="isee-header-div">
                    <!--                    面包屑 开始-->
                    <div style="width: 100%;display: inherit;">
                        <span class="aside-show" @click="iseeAsideShow">
                            <i :class="iseeData.asideShowIcon"></i>
                        </span>

                        <el-breadcrumb style="line-height: 50px" separator="/">
                            <el-breadcrumb-item v-for="(item,index) in iseeData.breadcrumb" :key="index">{{item.title}}
                            </el-breadcrumb-item>
                        </el-breadcrumb>
                    </div>
                    <!--                    面包屑 结束-->
                    <!--                    icon功能列表，可根据需要修改 开始-->
                    <div>
                        <ul class="isee-ul">
                            <li class="isee-li">
                                <i style="font-size: 20px" class="el-icon-bell"></i>
                            </li>
                            <li @click="iseeFullScreen" class="isee-li">
                                <span class="iconfont" style="font-size: 20px" v-html="iseeData.fullscreenIcon"></span>
                            </li>
                            <li class="isee-li" @click="iseeData.drawer = true">
                                <span class="iconfont" style="font-size: 20px">&#xe602;</span>
                            </li>
                        </ul>
                    </div>
                    <!--                    icon功能列表，可根据需要修改 结束-->
                    <!--                    avatar显示 开始-->
                    <div>
                        <el-dropdown @command="iseeOpenUrl">
                              <span class="el-dropdown-link">
                                  <el-avatar style="margin-top: 9px" :size="iseeData.avatar.size"
                                             :src="iseeData.avatar.url"></el-avatar>
                              </span>

                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item v-for="(item,index) in iseeData.avatar.list" :icon="item.icon"
                                                  :key="index" :command="index">{{item.title}}
                                </el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </div>
                    <!--                    avatar显示 结束-->
                </div>
                <div style="display: flex">
                    <!--                    标签页列表 开始-->
                    <span @click="iseeTagDivMove(1)" class="isee-tag-span">
                        <i class="el-icon-d-arrow-left"></i>
                    </span>
                    <div ref="iseeTagDiv" class="isee-tag-div">
                        <el-tag style="cursor:pointer;margin-right: 5px;" v-for="(item,index) in iseeData.tagList"
                                :key="index"
                                @click="iseeTagSwitch(item.url,item.index,item.breadcrumb)"
                                :effect="item.effect"
                                :type="item.type"
                                @close="iseeTagClose(item.url,index)"
                                size="medium"
                                :closable="item.closable"><i v-show="item.show" class="el-icon-view"></i> {{item.title}}
                        </el-tag>
                    </div>
                    <span @click="iseeTagDivMove(2)" class="isee-tag-span">
                        <i class="el-icon-d-arrow-right"></i>
                    </span>
                    <!--                    标签页列表 结束-->
                    <!--                    标签页集中操作 开始-->
                    <div style="float: right;margin-left: 10px">
                        <el-dropdown @command="iseeTagCommandClose">
                          <span class="el-dropdown-link">
                              <i class="el-icon-arrow-down isee-el-icon-arrow-down"></i>
                          </span>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item command="1">关闭当前标签页</el-dropdown-item>
                                <el-dropdown-item command="2">关闭其它标签页</el-dropdown-item>
                                <el-dropdown-item command="3">关闭全部标签页</el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </div>
                    <!--                    标签页集中操作 结束-->
                </div>

                <!--抽屉式展示-->
                <el-drawer
                        title="iseeAdmin"
                        :visible.sync="iseeData.drawer"
                        :direction="iseeData.direction"
                        :show-close="iseeData.showClose"
                        custom-class="isee-drawer-info"
                >
                    <el-divider></el-divider>
                    <div style="font-size: 14px">
                        <p class="isee-title">版本信息</p>
                        <ul class="isee-drawer-ul">
                            <li>
                                当前版本：iseeAdmin-v{{iseeData.version}}
                            </li>
                            <li>
                                基于框架：vue v2.6.10，element v2.12.0
                            </li>
                            <li>
                                下载地址：
                                <el-link type="primary" :underline="false" href="https://gitee.com/youge/iseeadmin"
                                         target="_blank">码云
                                </el-link>
                                |
                                <el-link type="primary" :underline="false" href="https://github.com/fukedi/iseeadmin"
                                         target="_blank">github
                                </el-link>
                            </li>
                        </ul>
                    </div>
                    <el-divider></el-divider>
                    <div style="font-size: 14px">
                        <p class="isee-title">关于版权</p>
                        <ul class="isee-drawer-ul">
                            <li>
                                iseeAdmin完全开源，可免费使用
                            </li>
                            <li>
                                QQ交流群：927049524
                            </li>
                        </ul>
                    </div>
                </el-drawer>
                <!--抽屉式展示 结束-->
            </el-header>

            <el-main>
                <!--                主内容展示-->
                <div>
                    <el-card class="box-card">
                        <p style="padding: 8px 16px;font-size: 14px;border-radius:4px;border-left: 5px solid #50bfff ">
                            文章列表
                        </p>
                        <el-divider></el-divider>

                        <div style="display: flex;">
                            <div style="width: 75%">
                                <el-button-group>
                                    <el-button round size="mini" type="danger" @click="del" icon="el-icon-delete">删除
                                    </el-button>
                                    <el-button round size="mini" type="primary" @click="add"
                                               icon="el-icon-circle-plus-outline">添加
                                    </el-button>
                                </el-button-group>
                            </div>
                            <div style="display: flex">
                                <el-cascader style="margin-right: 5px" placeholder="请选择分类" size="mini"
                                             :options="categoryList" ref="categoryCascaderSearch"
                                             clearable></el-cascader>
                                <el-input size="mini" placeholder="请输入文章标题" v-model="searchData.searchVal"
                                          class="input-with-select">
                                    <el-button type="primary" @click="search" slot="append"
                                               icon="el-icon-search"></el-button>
                                </el-input>
                            </div>
                        </div>
                    </el-card>
                    <el-card class="box-card">
                        <template>
                            <el-table
                                    v-loading="loading"
                                    element-loading-text="正在提交，请稍等。。。"
                                    ref="multipleTable"
                                    :data="listData.data"
                                    tooltip-effect="dark"
                                    style="width: 100%;text-align: center"
                                    size="mini"
                                    height="360"
                                    highlight-current-row
                                    @selection-change="rowSelect"
                            >
                                <el-table-column
                                        type="selection"
                                        width="55">
                                </el-table-column>
                                <el-table-column
                                        label="ID"
                                        width="50">
                                    <template slot-scope="scope">{{ scope.row.id }}</template>
                                </el-table-column>
                                <el-table-column
                                        prop="name"
                                        label="标题"
                                        width="400">
                                </el-table-column>
                                <el-table-column
                                        prop="author"
                                        label="作者"
                                        width="120">
                                </el-table-column>
                                <el-table-column
                                        prop="category.name"
                                        label="分类"
                                        width="120">
                                </el-table-column>
                                <el-table-column
                                        prop="click_rate"
                                        label="点击率"
                                        width="200">
                                </el-table-column>
                                <el-table-column
                                        label="权重"
                                        width="150">
                                    <template slot-scope="scope">
                                        <el-input style="width: 80px"
                                                  size="mini"
                                                  max="1000"
                                                  min="0"
                                                  placeholder="请输入内容"
                                                  @change="changeSortWeight"
                                                  v-model="scope.row.sort_weight">
                                        </el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                        label="状态"
                                        width="180">
                                    <template slot-scope="scope">
                                        <el-switch
                                                v-model="scope.row.status"
                                                :active-value="1"
                                                :inactive-value="0"
                                                @change="changStatus"
                                                active-color="#13ce66"
                                                inactive-color="#ff4949">
                                        </el-switch>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                        prop="add_time"
                                        label="发布时间"
                                        width="120">
                                </el-table-column>
                                <el-table-column
                                        fixed="right"
                                        label="操作"
                                        width="100">
                                    <template slot-scope="scope">
                                        <el-button @click="show(scope.row,scope.$index)" type="text" size="mini">查看
                                        </el-button>
                                        <el-button @click="edit(scope.row,scope)" type="text" size="mini">编辑</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </template>
                        <div style="margin: 20px;">
                            <el-pagination
                                    background
                                    @size-change="handleSizeChange"
                                    @current-change="handleCurrentChange"
                                    :current-page="listData.currentPage"
                                    :page-sizes="listData.pageSizes"
                                    :page-size="listData.pageSize"
                                    layout="total, sizes, prev, pager, next, jumper"
                                    :total="listData.total">
                            </el-pagination>
                        </div>
                    </el-card>

                    <el-dialog title="文章信息" :visible.sync="formData.visible" width="800px">
                        <el-form size="small" :model="formData" :rules="rules" ref="formData" label-width="100px">
                            <el-tabs v-model="activeName" @tab-click="handleClick">
                                <el-tab-pane label="基础" name="1">
                                    <el-form-item label="标题" prop="name">
                                        <el-input v-model="formData.name" class="form-item-width">
                                        </el-input>
                                    </el-form-item>
                                    <el-form-item label="作者" prop="author">
                                        <el-input v-model="formData.author" class="form-item-width">
                                        </el-input>
                                    </el-form-item>
                                    <el-form-item label="分类" prop="categoryId">
                                        <el-cascader v-model="formData.categoryId" class="form-item-width"
                                                     placeholder="请选择分类"
                                                     :options="categoryList" ref="categoryCascader"
                                                     clearable></el-cascader>
                                    </el-form-item>
                                    <el-form-item label="权重" prop="sortWeight">
                                        <el-input v-model.number="formData.sortWeight"
                                                  class="form-item-width"></el-input>
                                    </el-form-item>

                                    <el-form-item label="启用" prop="status">
                                        <el-switch
                                                v-model="formData.status"
                                                :active-value="1"
                                                :inactive-value="0"
                                                active-color="#13ce66"
                                                inactive-color="#ff4949">
                                        </el-switch>
                                    </el-form-item>

                                </el-tab-pane>
                                <el-tab-pane label="内容" name="2">
                                    <div ref="editor" style="margin-bottom: 10px;height: 300px">

                                    </div>
                                </el-tab-pane>
                            </el-tabs>

                            <el-form-item>
                                <el-button type="primary" @click="submitForm('formData')">保存</el-button>
                                <el-button @click="resetForm('formData')">重置</el-button>
                            </el-form-item>
                        </el-form>
                    </el-dialog>
                </div>
                <!--                主内容展示 结束-->
            </el-main>
        </el-container>
    </el-container>
</div>
<script>

  const item = [
    {
      id: 1,
      name: '九寨沟景区单日限流上调至8千人次，目前仍仅对团队游客开放',
      author: '原创',
      category: {
        ids: ['1', '2', '4'],
        name: '科技'
      },
      click_rate: 2020,
      sort_weight: 99,
      status: 0,
      add_time: '2016-05-02',
    }, {
      id: 2,
      name: '叙利亚库尔德人与土耳其之战：民族冲突还是意识形态之争？',
      author: '互联网',
      category: {
        ids: ['1', '3', '8'],
        name: '军事'
      },
      click_rate: 2220,
      sort_weight: 66,
      status: 1,
      add_time: '2016-07-02',
    }, {
      id: 3,
      name: '叙利亚库尔德人与土耳其之战：民族冲突还是意识形态之争？',
      author: '互联网',
      category: {
        ids: ['1', '2', '4'],
        name: '科技'
      },
      click_rate: 2220,
      sort_weight: 66,
      status: 1,
      add_time: '2016-07-02',
    }, {
      id: 4,
      name: '叙利亚库尔德人与土耳其之战：民族冲突还是意识形态之争？',
      author: '互联网',
      category: {
        ids: ['1', '2', '4'],
        name: '科技'
      },
      click_rate: 2220,
      sort_weight: 66,
      status: 1,
      add_time: '2016-07-02',
    }, {
      id: 5,
      name: '叙利亚库尔德人与土耳其之战：民族冲突还是意识形态之争？',
      author: '互联网',
      category: {
        ids: ['1', '2', '4'],
        name: '科技'
      },
      click_rate: 2220,
      sort_weight: 66,
      status: 1,
      add_time: '2016-07-02',
    }, {
      id: 6,
      name: '叙利亚库尔德人与土耳其之战：民族冲突还是意识形态之争？',
      author: '互联网',
      category: {
        ids: ['1', '2', '4'],
        name: '科技'
      },
      click_rate: 2220,
      sort_weight: 88,
      status: 0,
      add_time: '2016-07-02',
    },
  ];
  const iseeAvatar = {
    url: '/static/images/avatar01.gif',
    size: 32,
    list: [
      {
        index: '',
        indexPath: [],
        icon: 'el-icon-user-solid',
        url: '',
        target: '_self',
        title: 'admin',
      }, {
        index: '6-1-0',
        indexPath: ["6", "6-1", "6-1-0"],
        icon: 'el-icon-tickets',
        url: '/pages/sets/myset/profile.html',
        target: '_self',
        title: '基本资料',
      }, {
        index: '6-1-1',
        indexPath: ["6", "6-1", "6-1-1"],
        icon: 'el-icon-edit-outline',
        url: '/pages/sets/myset/password.html',
        target: '_self',
        title: '修改密码',
      }, {
        index: '',
        indexPath: [],
        icon: 'el-icon-switch-button',
        url: '',
        target: '_self',
        title: '安全退出',
      },
    ]
  }
  var iseemenu = {
    props: ['menu'],
    name: 'iseemenu',
    template: `
    <div>
        <template v-for="item in menu">
            <el-submenu :index="item.index" v-if="item.children.length">
                <template slot="title">
                    <i :class="item.icon"></i>
                    <span slot="title">{{item.title}}</span>
                </template>
                <iseemenu :menu="item.children"></iseemenu>
            </el-submenu>
            <el-menu-item :index="item.index" v-else>
                <i :class="item.icon"></i>
                <span slot="title">{{item.title}}</span>
            </el-menu-item>
        </template>
    </div>`,
  }

  var app = new Vue({
    el: '#app',
    components: {
      iseemenu
    },
    data: {
      iseeData: {
        version: iseeAdmin.version,
        drawer: false,
        direction: 'rtl',
        showClose: false,
        status: false,
        show: true,
        asideShow: iseeAdmin.asideShow,
        asideShowIcon: iseeAdmin.asideShowIcon,
        fullscreen: false,
        fullscreenIcon: '&#xe610;',
        defaultActive: iseeAdmin.defaultActive,
        tagList: iseeAdmin.tagList,
        breadcrumb: iseeAdmin.breadcrumb,
        menu: iseeMenu,
        avatar: iseeAvatar
      },
      /*your data*/
      listData: {
        currentPage: 2,
        pageSize: 20,
        pageSizes: [20, 40, 60, 80, 100],
        total: 600,
        data: item,
      },
      searchData: {
        categoryId: 0,
        searchVal: '',
      },
      rowSelected: [],
      formData: {
        id: 0,
        name: '',
        author: '',
        categoryId: null,
        status: 1,
        sortWeight: 0,
        visible: false
      },
      rules: {
        name: [
          {required: true, message: '请输入名字', trigger: 'blur'},
          {min: 3, max: 30, message: '长度在 3 到 30 个字符', trigger: 'blur'}
        ],
        author: [
          {required: true, message: '请输入作者', trigger: 'blur'},
          {min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur'}
        ],
        categoryId: [
          {required: true, message: '请选择分类', trigger: 'blur'},
        ],
        sortWeight: [
          {type: 'integer', message: '必须为整数', trigger: 'blur'},
          {
            validator: function (rule, value, callback) {
              if (value < 0) {
                callback(new Error("权重必须大于0"));
              } else if (value > 1000) {
                callback(new Error("权重必须小于1000"));
              } else {
                callback();
              }
            }, trigger: 'blur'
          }
        ],
      },
      categoryList: [{
        value: '1',
        label: '新闻中心',
        children: [{
          value: '2',
          label: '国内新闻',
          children: [{
            value: '4',
            label: '科技'
          }, {
            value: '5',
            label: '汽车'
          }, {
            value: '6',
            label: '房产'
          }, {
            value: '7',
            label: '时尚'
          }]
        }, {
          value: '3',
          label: '国际新闻',
          children: [{
            value: '8',
            label: '军事'
          }, {
            value: '9',
            label: '财政'
          }]
        }]
      }, {
        value: '10',
        label: '产品展示',
        children: [{
          value: '11',
          label: '产品1',
          children: [{
            value: '12',
            label: '产品11-1'
          }, {
            value: '13',
            label: '产品11-2'
          }, {
            value: '14',
            label: '产品11-3'
          }, {
            value: '15',
            label: '产品11-4'
          }, {
            value: '16',
            label: '产品11-5'
          }]
        }]
      }, {
        value: '17',
        label: '团队管理',
        children: [{
          value: '18',
          label: '生产中心'
        }, {
          value: '19',
          label: '技术中心'
        }, {
          value: '20',
          label: '信息中心'
        }]
      }],
      loading: false,
      activeName: '1',
      quill: null,
    },
    methods: {
      iseeTagSwitch(url, index, breadcrumb) {
        iseeAdmin.iseeTagSwitch(url, index, breadcrumb, this.iseeData)
      },

      iseeTagClose(url, index) {
        iseeAdmin.iseeTagClose(url, index, this.iseeData)
      },

      iseeTagCommandClose(command) {
        iseeAdmin.iseeTagCommandClose(command, this.iseeData)
      },

      iseeMenuOpen(key, keyPath) {
        iseeAdmin.iseeMenuOpen(key, keyPath, this.iseeData)
      },

      iseeFullScreen() {
        iseeAdmin.iseeFullScreen(this.iseeData)
      },

      iseeAsideShow() {
        iseeAdmin.iseeAsideShow(this.iseeData)
      },
      iseeOpenUrl(command) {
        iseeAdmin.iseeMenuOpen(this.iseeData.avatar.list[command].index, this.iseeData.avatar.list[command].indexPath, this.iseeData)
      },
      iseeTagDivMove(flag) {
        flag == 1 ? this.$refs.iseeTagDiv.scrollLeft += 80 : this.$refs.iseeTagDiv.scrollLeft -= 80
      },
      /*your methods*/
      createEditor() {
        return new Quill(this.$refs.editor, {
          theme: 'snow',
          modules: {
            toolbar: [
              ['bold', 'italic', 'underline', 'strike'],        // toggled buttons
              ['blockquote', 'code-block'],
              ['link', 'image'],
              [{'list': 'ordered'}, {'list': 'bullet'}],     // superscript/subscript
              [{'indent': '-1'}, {'indent': '+1'}],          // outdent/indent
              [{'header': [1, 2, 3, 4, 5, 6, false]}],

              [{'color': []}, {'background': []}],          // dropdown with defaults from theme
              [{'align': []}],
              ['clean']
            ]
          }
        });
      },


      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$message.success('校验通过！可以提交');
            console.log('提交的数据如下')
            console.log(this[formName])

            const html = this.$refs.editor.children[0].innerHTML
            console.log('html')
            console.log(html)


            this[formName].visible = false
            this.$message({
              message: '校验通过！可以提交',
              type: 'success'
            });
          } else {
            this.$message.error('校验不通过！不能提交')
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      show(row, obj) {
        console.log('查看');
        console.log(row);
        console.log(row.category.ids);
        console.log(obj);
        this.formData.id = row.id
        this.formData.name = row.name
        this.formData.author = row.author
        this.formData.sortWeight = row.sort_weight
        this.formData.status = row.status
        this.formData.categoryId = row.category.ids

        if (this.quill == null) {
          this.$nextTick(_ => {
            this.quill = this.createEditor()
          });
        }

        this.formData.visible = true
      },
      edit(row, obj) {
        console.log('编辑');
        console.log(row);
        console.log(obj);
      },
      search() {
        console.log('当前搜索值：' + this.searchData.searchVal)
        let categoryObj = this.$refs.categoryCascaderSearch.getCheckedNodes(true)
        if (categoryObj.length > 0) {
          this.searchData.categoryId = categoryObj[0].value
        }
        console.log('当前搜索分类id：' + this.searchData.categoryId)
      },
      rowSelect(rowSelected) {
        console.log('rowSelected')
        console.log(rowSelected)
        this.rowSelected = rowSelected;
      },
      del() {
        let ids = []
        console.log('要删除的ids')
        this.rowSelected.forEach(row => {
          console.log('id:' + row.id)
          ids.push(row.id)
        })
        console.log(ids)
      },
      add() {
        console.log('add')
        this.formData.visible = true
        if (this.quill == null) {
          this.$nextTick(_ => {
            this.quill = this.createEditor()
          });
        }

      },
      changeSortWeight(val) {
        console.log('change sort weight')
        console.log(val)

        if (!/^\d+$/.test(val)) {
          this.$message.error('权重必须为整数')
          return
        }
        if (val<0||val>1000) {
          this.$message.error('权重必须为大于0小于1000的整数')
          return
        }
        this.loading = true
        setTimeout(() => {
          this.loading = false
        }, 2000)
      },
      changStatus(val) {
        console.log('changStatus')
        console.log(val)
        this.loading = true
        setTimeout(() => {
          this.loading = false
        }, 2000)
      },
      handleClick(tab, event) {
        // console.log(tab, event);
      }
    },
    beforeMount() {
      iseeAdmin.init(this.iseeData)
      /*your beforeMount*/
    },
    mounted() {


    }
  });
</script>
</body>

</html>

